package com.wy.hwreader.txtreader;


import com.wy.hwreader.data.ViewSettingsDB;
import com.wy.hwreader.readermain.Book;
import com.wy.hwreader.readermain.BookDataLoadProcessor;
import com.wy.hwreader.readermain.CallBack;
import com.wy.hwreader.readermain.ReaderContex;
import com.wy.hwreader.readermain.ReaderException.Type;
import com.wy.hwreader.readermain.ReaderSettingInitProcessor;

public class TxtReaderSettingInitProcessor extends ReaderSettingInitProcessor {

    @Override
    public void Process(CallBack<Type> callBack, ReaderContex readerContex) {
        TxtReaderContex contex = (TxtReaderContex) readerContex;
        getHistorySettings(contex);
        TxtPaintContex txtPaintContex = new TxtPaintContex();
        txtPaintContex.init(contex);
        contex.mPaintContex = txtPaintContex;

        BookDataLoadProcessor processor = new TxtDataLoadProcessor();
        processor.Process(callBack, contex);

    }

    private void getHistorySettings(TxtReaderContex contex) {
        ViewSettingsDB db = new ViewSettingsDB(contex.mContext);
        db.CreateTable();
        Book book = contex.mBook;
        TxtReaderViewSettings setting = (TxtReaderViewSettings) db.getViewSettingMsg(book.BOOKHashName,
                TxtReaderViewSettings.class);
        if (setting != null) {
            contex.mViewSetting = setting;
        } else {
            contex.mViewSetting = new TxtReaderViewSettings();
        }
        db.close();
    }

}
